/// Hash function for a generic pointer.
/// This function takes a reference to any type and returns a `usize` hash value.
/// The hash value is derived from the memory address of the referenced object.
pub fn pointer_hash<T>(location: &T) -> usize {
    // The memory address of the reference is used as the hash value.
    location as *const T as usize
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_pointer_hash() {
        // Create a concrete type for testing.
        let value: i32 = 42;

        // Calculate the hash value.
        let hash_value = pointer_hash(&value);

        // Verify that the hash value is consistent.
        assert_eq!(hash_value, &value as *const i32 as usize);

        // Test with another value to ensure consistency.
        let another_value: i32 = 100;
        let another_hash_value = pointer_hash(&another_value);
        assert_eq!(another_hash_value, &another_value as *const i32 as usize);

        // Ensure that different values produce different hashes.
        assert_ne!(hash_value, another_hash_value);
    }
}
